﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using DAL;
using System.Data;

namespace BLL
{
    public class ContestService
    {
        ContestsDAL contestDAL = new ContestsDAL();
        ProceduresDAL procedureDAL = new ProceduresDAL();

        public void CreateContest(BoContests contest)
        {
            contestDAL.Insert(contest);
        }

        public void UpdateContest(BoContests contest)
        {
            contestDAL.Update(contest);
        }

        public void DeleteContest(BoContests contest)
        {
            contestDAL.Delete(contest.CON_ID);
            procedureDAL.DeleteProceduresByContest(contest.CON_ID);
        }
        public void DeleteContestByCompetitionId(string competitionId)
        {
            contestDAL.DeleteContestByCompetitionId(competitionId);
             IList<BoContests> contestlist = GetContestByCompetition(competitionId);   
        }

        public BoContests getContest(string id)
        {
            return contestDAL.GetModel(id);
        }

        public IList<BoContests> getAllContests()
        {
            return contestDAL.GetAllContests();
        }

        public IList<BoContests> getInnerContests()
        {
            return contestDAL.GetAllInnerContestsBy();
        }

        /// <summary>
        /// 得到分页的数据列表
        /// </summary>
        /// <param name="orderCon">排序条件</param>
        /// <param name="sqlCon">查询条件</param>
        /// <param name="pagesize">每页显示大小</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="records">返回查询到的记录</param>
        /// <returns>返回对象列表</returns>
        public IList<BoContests> GetPagerInnerContests(string sqlCon, string orderCon, int pagesize, int pageIndex, out int records)
        {
            return contestDAL.GetPagerInnerContests(sqlCon, orderCon, pagesize, pageIndex, out records);
        }
        public IList<BoContests> GetPagerInnerContestsByAcademy2(string academyId, int pagesize, int pageIndex, out int records)
        {
            return contestDAL.GetPagerInnerContests2(academyId, "", pagesize, pageIndex, out records);
        }
        public IList<BoContests> GetPagerInnerContestsByAcademy(string academyId, int pagesize, int pageIndex, out int records)
        {
            return contestDAL.GetPagerInnerContests1(academyId, "", pagesize, pageIndex, out records);
        }
        public IList<BoContests> GetPagerInnerContestsByTeacher(string teacherId, int pagesize, int pageIndex, out int records)
        {
            return contestDAL.GetPagerInnerContests1("", teacherId, pagesize, pageIndex, out records);
        }
        public IList<BoContests> GetPagerInnerContestsByTeacher2(string teacherId, int pagesize, int pageIndex, out int records)
        {
            return contestDAL.GetPagerInnerContests2("", teacherId, pagesize, pageIndex, out records);
        }
        /// <summary>
        /// 根据条件获取倩top行数据
        /// </summary>
        /// <param name="top">数据条数</param>
        /// <param name="sqlCon">条件</param>
        /// <param name="orderCon">排序条件</param>
        /// <returns>返回top行数据</returns>
        public IList<BoContests> getInnerContests(int top, string sqlCon, string orderCon)
        {
            return contestDAL.getInnerContests(top, sqlCon, orderCon);
        }

        public IList<BoContests> getOuterContests()
        {
            return contestDAL.GetAllOuterContests();
        }

        public IList<BoContests> getInnerContestsByAcademy(string academyId)
        {
            return contestDAL.GetAllInnerContestsByAcademy(academyId);
        }

        public IList<BoContests> getOuterContestsByAcademy(string academyId)
        {
            return contestDAL.GetAllOuterContestsByAcademy(academyId);
        }

        public void CreateProcedure(BoProcedures proc)
        {
            procedureDAL.Insert(proc);
        }

        public void UpdateProcedure(BoProcedures proc)
        {
            procedureDAL.Update(proc);
        }

        public void DeleteProcedure(BoProcedures proc)
        {
            procedureDAL.Delete(proc.PRO_ID);
        }

        public BoProcedures GetProcedure(string procId)
        {
            return procedureDAL.GetModel(procId);
        }
        /// <summary>
        /// 通过竞赛对象得到竞赛安排列表
        /// </summary>
        /// <param name="contest">竞赛对象</param>
        /// <returns>返回赛安排列表</returns>
        public IList<BoProcedures> GetContestProcedures(BoContests contest)
        {
            return procedureDAL.GetProceduresByContest(contest.CON_ID);
        }

        public IList<BoProcedures> GetProceduresByTime(DateTime date)
        {
            return procedureDAL.GetProceduresByTime(date);
        }

        /// <summary>
        /// 通过时间和条数拿到相对应的数据
        /// </summary>
        /// <param name="topnumber"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public IList<BoProcedures> GetProceduresByTime(int topnumber, DateTime date)
        {
            return procedureDAL.GetProceduresByTime(topnumber,date);
        }
        // <summary>
        /// 通过过程id来获得相应的一条数据
        /// </summary>
        /// <param name="pro_id"></param>
        /// <returns></returns>
        public BoProcedures GetProceduresById(string id)
        {
            return procedureDAL.GetProceduresByProId(id);
        }

        public IList<BoContests> GetContestByCompetition(string comId) 
        {
            return contestDAL.GetContestByCompetition(comId);
        }
        /// <summary>
        /// 根据竞赛id得到竞赛视图
        /// </summary>
        /// <param name="conId">竞赛id</param>
        /// <returns>返回表格</returns>
        public BoContests GetV_Contest(string conId)
        {
            return contestDAL.GetV_Contest(conId);
        }
        /// <summary>
        /// 根据top数目及条件得到相应的数据
        /// </summary>
        /// <param name="top">数目</param>
        /// <param name="Constr">筛选条件</param>
        /// <param name="order">排序条件</param>
        /// <returns>返回数据表格</returns>
        public DataTable GetAllV_Contest(int top, string Constr,string order)
        {
            return contestDAL.GetAllV_Contest(top, Constr,order);
        }
        /// <summary>
        /// 根据数据行数获取表格
        /// </summary>
        /// <param name="start">开始数据条数</param>
        /// <param name="end">结束数据集条数</param>
        /// <param name="sqlcon">查询条件</param>
        /// <returns>返回相应的表格</returns>
        public DataTable GetPage(string start, string end, string orderCon, string sqlcon)
        {
            return contestDAL.GetPage(start, end, orderCon, sqlcon);
        }

        /// <summary>
        /// 根据数据行数获取步骤表格
        /// </summary>
        /// <param name="start">开始数据条数</param>
        /// <param name="end">结束数据条数</param>
        /// <param name="orderCon">排序条件</param>
        /// <param name="sqlcon">查询条件</param>
        /// <returns>查询条件</returns>
        public DataTable GetParPage(string start, string end, string orderCon, string sqlcon)
        {
            return contestDAL.GetParPage(start, end, orderCon, sqlcon);
        }

       
    }
}
